package stream;

import java.util.*;
//现在有一个菜品集合，需要找出菜品中的卡路里小于400的菜品并且按照卡路里多少进行排序
public class TestDishWithNomarl {
        public static void main(String[] args) {
            List<Dish> menu= Arrays.asList(
                    new Dish("pork",800),
                    new Dish("beef",700),
                    new Dish("chicken",400),
                    new Dish("french fries",530),
                    new Dish("rice",350),
                    new Dish("fruit",120),
                    new Dish("pizza",550));
            List<Dish> lowCaloriesDish=new ArrayList<>();
            for(Dish d:menu)
            {
                if(d.getCalories()<400)
                    lowCaloriesDish.add(d);
            }
            Collections.sort(lowCaloriesDish,new Comparator<Dish>() {
                @Override
                public int compare(Dish o1, Dish o2) {
                    return Integer.compare(o1.getCalories(), o2.getCalories());
                }
            });
            for(Dish d:lowCaloriesDish)
                System.out.println(d.getName()+"  "+d.getCalories());
        }
    }
